package com.example.demo.controller.AuthorControl;

import com.example.demo.entity.BackResponseEntity;
import com.example.demo.entity.requestJson.AInsertChapterReq;
import com.example.demo.entity.requestJson.ALockChapterReq;
import com.example.demo.entity.requestJson.DeleteReq;
import com.example.demo.entity.responseJson.AllChapterToBookRes;
import com.example.demo.entity.responseJson.ChapterContentRes;
import com.example.demo.entity.responseJson.ListResult;
import com.example.demo.service.AChapterService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 杨丽辉
 * @date : 2021/3/5 14:03
 * @description:
 */
@RestController
@RequestMapping("/author/chapter")
@Api(value = "章节管理接口", tags = "章节管理接口")
public class AChapterController {
    @Autowired
    private AChapterService aChapterService;

    @ApiOperation(value = "发布新章节内容接口", notes = "章节名称格式为：第几章  章节名称")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/insertchapter")
    public BackResponseEntity<Object> insertChapter(@RequestBody AInsertChapterReq aInsertChapterReq) {
        return aChapterService.insertChapter(aInsertChapterReq);
    }

    @ApiOperation(value = "修改章节内容接口", notes = "章节名称格式为：第几章  章节名称")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/updatechapter")
    public BackResponseEntity<Object> updateChapter(@RequestBody AInsertChapterReq aInsertChapterReq){
        return aChapterService.updateChapter(aInsertChapterReq);
    }

    @ApiOperation(value = "查询书籍所有章节接口", notes = "参数名:id,即bookId")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/querychapter")
    public BackResponseEntity<ListResult<List<AllChapterToBookRes>>> queryChapter(DeleteReq deleteReq) {
        return aChapterService.queryAllChapter(deleteReq);
    }

    @ApiOperation(value = "查询章节内容接口", notes = "参数名:id,即chapterId")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/querycontent")
    public BackResponseEntity<List<ChapterContentRes>> queryContent(DeleteReq deleteReq) {
        return aChapterService.queryChapterContent(deleteReq);
    }

    @ApiOperation(value = "锁定章节接口", notes = "")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/lockchapter")
    public BackResponseEntity<Object> lockChapter(ALockChapterReq aLockChapterReq) {
        return aChapterService.lockChapter(aLockChapterReq);
    }
}
